package com.hj.controller;

import com.hj.model.AdvanceResponse;
import com.hj.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author haoshen
 * @version 1.0
 */
@SuppressWarnings("all")
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 添加订单
     *
     * @param request
     * @return
     */
    @GetMapping("/addOrder")
    public AdvanceResponse<Object> addOrder(HttpServletRequest request) {
        return orderService.addOrder(request);
    }

    /**
     * 查看订单
     */
    @GetMapping("/selOrder")
    public AdvanceResponse<Object> selOrder(HttpServletRequest request) {
        return orderService.selOrder(request);
    }

    /**
     * 删除订单
     */
    @GetMapping("/delOrder")
    public AdvanceResponse<Object> delOrder(HttpServletRequest request) {
        return orderService.delOrder(request);
    }

    /**
     * 付款
     *
     * @param way 付款方式
     */
    @GetMapping("/makeOrder")
    public AdvanceResponse<Object> makeOrder(HttpServletRequest request, Integer way) {
        return orderService.makeOrder(request, way);
    }

    /**
     * 查询已经完成订单
     */
    @GetMapping("/paidOrder")
    public AdvanceResponse paidOrder() {
        return orderService.paidOrder();
    }

    /**
     * 由订单号查订单
     */
    @GetMapping("selOrderByOrderId")
    public AdvanceResponse selOrderByOrderId(String orderNo) {
        return orderService.selOrderByOrderId(orderNo);
    }

    /**
     * 由订单号查payInfo信息
     */
    @GetMapping("/selPayInfoByOrderNo")
    public AdvanceResponse selPayInfoByOrderNo(@RequestParam(required = true, defaultValue = "1") Integer num,
                                               @RequestParam(required = true, defaultValue = "5") Integer size,
                                               String orderNo) {
        return orderService.selPayInfoByOrderNo(num, size, orderNo);
    }

    /**
     * 删除payInfo信息
     */
    @DeleteMapping("/delPayInfo")
    public AdvanceResponse delPayInfo(@RequestBody List<Integer> ids) {
        return orderService.delPayInfo(ids);
    }
}
